package logic

import (
	"C/Rpc/model/mysql"
	"context"
	"fmt"

	"C/Rpc/internal/svc"
	"C/Rpc/shop"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodShowLogic {
	return &GoodShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 商品详情
func (l *GoodShowLogic) GoodShow(in *shop.GoodShowRequest) (*shop.GoodShowResponse, error) {
	// todo: add your logic here and delete this line
	g := mysql.Good{}
	getShow, err := g.GetShow(int(in.GoodId))

	if err != nil {
		return nil, fmt.Errorf("查收失败")
	}
	var show []*shop.ShowList
	for _, good := range getShow {
		show = append(show, &shop.ShowList{
			UserId:     int64(good.UserId),
			GoodsTitle: good.GoodsTitle,
			GoodsStock: int64(good.GoodsStock),
			GoodsImage: good.GoodsImage,
			GoodsPrice: float32(good.GoodsPrice),
			GoodsLike:  int64(good.GoodsLike),
			Status:     int64(good.Status),
			Id:         int64(good.ID),
		})
	}
	return &shop.GoodShowResponse{
		Show: show,
	}, nil
}
